using System;
using System.IO;
using EnvDTE;
using Microsoft.WowAddonStudio.Lua.LanguageService.Tests.WowCommonTestLibrary.Mocks;
using Microsoft.WowAddonStudio.ProjectRefactor;
using NUnit.Framework;

namespace WowProjectPackage.Tests.ProjectRefactor
{
	[TestFixture]
	public class FrameXmlMergerFactoryTest : GeneralDTETestBase
	{
		private const string Frame_Xml_New_Name = "Frame.xml";
		private readonly string currentDir = String.Concat(Environment.CurrentDirectory, @"\Resources");
		private FrameXmlMergerFactory mergerFactory;
		private SimpleTestServiceLocator serviceLocator;

		#region SetUp

		/// <summary>
		/// Sets up.
		/// </summary>
		[SetUp]
		public override void SetUp()
		{
			base.SetUp();

			serviceLocator = new SimpleTestServiceLocator();
			mergerFactory = new FrameXmlMergerFactory(serviceLocator);
		}

		#endregion

		#region TearDown

		/// <summary>
		/// Tears down.
		/// </summary>
		[TearDown]
		public override void TearDown()
		{
			base.TearDown();
			((MockDTE)SimpleTestServiceLocator.Get<DTE>()).SetMockDocuments(null);
		}

		#endregion

		#region Tests

		/// <summary>
		/// Test_s the create file merger.
		/// </summary>
		[Test(Description = "")]
		public void Test_CreateFileMerger()
		{
			var merger = mergerFactory.CreateMerger("Resources\\Frame.xml");
			Assert.IsNotNull(merger);
			Assert.IsInstanceOfType(typeof(FrameXmlFileMerger), merger);
		}

		/// <summary>
		/// Test_s the create external file merger.
		/// </summary>
		[Test(Description = "")]
		public void Test_CreateExternalFileMerger()
		{
			Assert.IsNotNull(DTE);

			InitializeMockObjects("");
			var props = ((MockProperties)SimpleTestServiceLocator.Get<ProjectItem>().Properties);
			if (!props.ContainsKey("FullPath"))
				props.Add("FullPath", CreateMockProperty(props, "FullPath", Path.Combine(currentDir, Frame_Xml_New_Name)));

			var docs = new MockDocuments(SimpleTestServiceLocator.Get<DTE>(),
				((MockProjectItem)SimpleTestServiceLocator.Get<ProjectItem>()).Object.ToString(),
				new[] { SimpleTestServiceLocator.Get<ProjectItem>().Document });
			((MockDTE)SimpleTestServiceLocator.Get<DTE>()).SetMockDocuments(docs);

			var merger = mergerFactory.CreateMerger(Path.Combine(currentDir, "Frame.xml"));
			Assert.IsNotNull(merger);
			Assert.IsInstanceOfType(typeof(FrameXmlDocumentMerger), merger);
			
		}

		/// <summary>
		/// Test_s the frame XML merger factory init failed1.
		/// </summary>
		[Test(Description = "")]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Test_FrameXmlMergerFactoryInitFailed1()
		{
			new FrameXmlMergerFactory((IServiceProvider)null);
		}

		/// <summary>
		/// Test_s the frame XML merger factory init failed2.
		/// </summary>
		[Test(Description = "")]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Test_FrameXmlMergerFactoryInitFailed2()
		{
			new FrameXmlMergerFactory(null, null);
		}



		#endregion
	}
}